package 笔试.贝壳;

import java.util.Scanner;
import java.util.Stack;

public class Demo22 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt(); //组数
        int[] res = new int[T];
        for (int i = 0; i < T; i++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            Stack<Character> stack = new Stack<>();
            for (char c:str.toCharArray()){
                if(c=='(') {
                    stack.push(c);
                }else if(c==')' && !stack.isEmpty() && stack.peek()=='(' ){
                    stack.pop();
                }
            }
            res[i] = stack.size();
        }
        for(int t:res){
            System.out.println(t);
        }
    }
}
